<script setup>
import { computed } from "vue";
const props = defineProps(["loading", "gray", "delay", "fill"]);
const gray = computed(() => props.gray !== undefined);
const delay = computed(() => props.delay !== undefined);
const fill = computed(() => props.fill !== undefined);
</script>

<template>
  <Transition name="loading">
    <div class="loading-layer" :class="{ gray, delay }" v-if="loading">
      <md-circular-progress indeterminate></md-circular-progress>
    </div>
  </Transition>
  <div class="fill" role="presenation" v-if="loading && fill"></div>
</template>

<style scoped>
.loading-enter-active,
.loading-leave-active {
  transition-property: opacity;
  transition-duration: var(--md-sys-motion-duration-short2);
  transition-timing-function: var(--md-sys-motion-easing-emphasized-decelerate);
}

.loading-enter-active.delay {
  transition-delay: 200ms;
}

.loading-enter-from,
.loading-leave-to {
  opacity: 0;
}

.loading-layer {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background-color: var(--md-sys-color-background);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-layer.gray {
  background-color: rgba(0, 0, 0, 0.2);
}

.material-table .loading-layer {
  border-radius: 24px;
}

.fill {
  height: 200px;
}
</style>